#ifndef __GAME_THREAD_POOL_H__
#define __GAME_THREAD_POOL_H__

#include "BS_thread_pool.hpp"
#include "SimpleSingleton.hpp"
#include "ServerConfigure.h"
#include "GameSingleton.h"

namespace PocketSurvival
{
    // 该线程池用于执行需要等待处理的异步处理，例如:子系统(Subsystem) 的 update 处理
    class GameThreadPool : public SimpleSingletonItem, public BS::thread_pool
    {
        friend class SimpleSingleton;
    protected:
        inline GameThreadPool() : BS::thread_pool(GameSingleton::serverConfigure->threadCount) {}
    };
    

    // 该线程池用于执行不用等待处理的异步处理
    // 但是当服务器关闭时，这里会阻塞等待线程池里面的任务执行完成
    class GameNoWaitThreadPool : public SimpleSingletonItem, protected BS::thread_pool
    {
        friend class SimpleSingleton;
        friend class ServerRoot;

    protected:
        inline GameNoWaitThreadPool() : BS::thread_pool(GameSingleton::serverConfigure->threadCount) {}

    public:
        template <typename F, typename... A>
        inline void push_task(F&& task, A&&... args)
        {
            BS::thread_pool::push_task(std::forward<F>(task), std::forward<A>(args)...);
        }
    };


    // 用于数据保存时的多线程处理
    class GameSaveThreadPool : public GameThreadPool
    {
        friend class SimpleSingleton;
    };

} // namespace PocketSurvial

#endif
